using System;
using System.Collections.Generic;
using Slqj.Common;
using Shc.Sql;
namespace Slqj.Data
{
    [Serializable]
    public class AuthRoles
        : BaseAuthRoles
    {
        #region 通用操作
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <returns></returns>
        public bool Insert()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {

                return DbManager.Current.Insert(ss, this);
            }
        }

        /// <summary>
        /// 新增数据,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
        public bool Insert(DbSession ss)
        {
            return DbManager.Current.Insert(ss, this);
        }

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {

                return DbManager.Current.Update(ss, this);
            }
        }

        /// <summary>
        /// 更新实体,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
        public bool Update(DbSession ss)
        {
            return DbManager.Current.Update(ss, this);
        }

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public bool Delete()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.Delete(ss, this);
            }
        }

        /// <summary>
        /// 删除实体,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
        public bool Delete(DbSession ss)
        {
            return DbManager.Current.Delete(ss, this);
        }

        /// <summary>
        /// 根据条件批量删除
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static bool Delete(Criterion[] criteria)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.DeleteEntities(ss, TableAuthRoles.Table, criteria);
            }
        }

        /// <summary>
        /// 根据条件使用事务批量删除
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static bool Delete(DbSession ss, Criterion[] criteria)
        {
            return DbManager.Current.DeleteEntities(ss, TableAuthRoles.Table, criteria);
        }

        /// <summary>
        /// 根据条件查询单个实体
        /// </summary>
        /// <returns></returns>
        public static AuthRoles Find(params Criterion[] criteria)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.Find<AuthRoles>(ss, criteria);
            }
        }

        /// <summary>
        /// 根据条件查询单个实体
        /// </summary>
        /// <returns></returns>
        public static AuthRoles Find(DbSession ss, params Criterion[] criteria)
        {
            return DbManager.Current.Find<AuthRoles>(ss, criteria);
        }

        /// <summary>
        /// 根据主键查询实体
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static AuthRoles FindByPK(params object[] keys)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.FindPK<AuthRoles>(ss, keys);
            }
        }

        /// <summary>
        /// 根据主键查询实体
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static AuthRoles FindByPK(DbSession ss, params object[] keys)
        {
            return DbManager.Current.FindPK<AuthRoles>(ss, keys);
        }

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindAll(Order[] orders, params Criterion[] criteria)
        {
            IList<AuthRoles> list = new List<AuthRoles>();
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                DbManager.Current.Query(ss, list, orders, criteria);
                return list;
            }
        }

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindAll(params Criterion[] criteria)
        {
            return FindAll(new Order[0], criteria);
        }

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindAll(DbSession ss, params Criterion[] criteria)
        {
            return FindAll(new Order[0], ss, criteria);
        }

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindAll(Order[] orders, DbSession ss, params Criterion[] criteria)
        {
            IList<AuthRoles> list = new List<AuthRoles>();

            DbManager.Current.Query(ss, list, orders, criteria);
            return list;
        }

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindByPage(int curPage, int pagesize, Order[] orders,
            params Criterion[] criteria)
        {
            IList<AuthRoles> list = new List<AuthRoles>();
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                DbManager.Current.Query(ss, list, curPage, pagesize, orders, criteria);
                return list;
            }
        }

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindByPage(int curPage, int pagesize, params Criterion[] criteria)
        {
            return FindByPage(curPage, pagesize, new Order[0], criteria);
        }

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindByPage(int curPage, int pagesize,
            DbSession ss, params Criterion[] criteria)
        {
            return FindByPage(curPage, pagesize, new Order[0], ss, criteria);
        }

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<AuthRoles> FindByPage(int curPage, int pagesize, Order[] orders,
            DbSession ss, params Criterion[] criteria)
        {
            IList<AuthRoles> list = new List<AuthRoles>();

            DbManager.Current.Query(ss, list, curPage, pagesize, orders, criteria);
            return list;
        }
        #endregion

        /// <summary>
        /// 获取角色权限列表，
        /// </summary>
        /// <returns>权限代码列表</returns>
        public string[] GetPermissionList()
        {
            if (this.PermissionsIDList == null)
            {
                return new string[0];
            }
            else
            {
                return this.PermissionsIDList.Split(new char[] { ',' });
            }
        }
    }
}
